package com.wkq.dao;

import com.wkq.domain.Role;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IRoleDao {

    //添加角色和资源权限的关系
    public int addPermissionToRole (@Param("roleId") String roleId,
                                    @Param("permissionList") List<String> permissionId);

    //根据角色id查询出角色的详细信息
    @Select(" select id, roleName, roleDesc from role where id = #{id} ")
    public Role findById (int id);

    //    根据用户id查询出用户具有哪些角色
    @Select(" select id, roleName, roleDesc from role as r right join users_role as u " +
            "on r.id = u.roleId where userId = #{userId} ")
    public List<Role> findAllByUserId(String userId);

    //    根据用户id查询出用户还未拥有的角色
    @Select(" select id, roleName, roleDesc from " +
            "(select userId, roleId from users_role where userId = #{userId}) as u " +
            "right join role as r on u.roleId = r.id where u.userId is null ")
    public List<Role> findOtherRole(String userId);

    @Select(" select id, roleName, roleDesc from role ")
    public List<Role> findAll();

    @Insert(" insert into role(roleName, roleDesc) values(#{roleName}, #{roleDesc}) ")
    public int save(Role role);
}
